<?php
/**
* 缓存管理测试页
*/
header('content-type:text/html; charset=utf-8');
class Resume_Page_CacheTest extends Resume_Page_Abstract
{
	
	/**
	* @param 
	*/
	public function validate(ME_Request $input, ME_Response $output)
	{
		$input->moduleName = trim($input->get('moduleName'));
                $input->moduleId = trim($input->get('moduleId'));

		$input->recursion  = (bool)$input->get('recursion');
		$input->ignore     = (array)$input->get('ignore');
		return true;
	}
	
	/**
	* 显示
	*/
	public function doDefault()
	{

		$str = '<li><a href="?c=CacheTest&a=register">注册模块</a></li>';
		$str .= '<li><a href="?c=CacheTest&a=refresh">生成数据</a></li>';
		$str .= '<li><a href="?c=CacheTest&a=show">显示数据</a></li>';
		echo $str;
		exit;
	}
	
	/**
	* 显示
	*/
	public function doShow(ME_Request $input)
	{
		if (!$input->moduleName) {
			die('ModuleName is empty!');
		}
		$param = array();
		switch ($input->moduleName) {
                    case 'Resume_Class':#模块固定数据
                        $param = array(
                            "moduleId"=>$input->moduleId,
                        );
                        break;
                    default :
				$param = array();
		}
		
		$cacheLoader = ME_DAL_GetCacheLoader::getInstance();
		$data = $cacheLoader->loadCacheObject($input->moduleName, $param);
		var_dump($data);
		exit;
	}
	
	
	
	/**
	* 注册
	*/
	public function doRegister(ME_Request $input)
	{
		$cacheModuleManager = ME_DAL_CacheModuleManager::getInstance();
		$cacheModuleManager->registerModule($input->moduleName, true)
		and die('注册“' . $input->moduleName . '”模块成功！')
		or die('注册“' . $input->moduleName . '”模块失败！');
	}
	
	/**
	* 生成
	*/
	public function doRefresh(ME_Request $input)
	{
		$param = array();
		switch ($input->moduleName) {
                   case 'Resume_Class':#模块固定数据
                        $param = array(
                            "moduleId"=>$input->moduleId,
                        );
                        break;
                   default :
                        $param = array();
                        break;
		}
		if ($input->recursion) {
			$param['recursion'] = 1;
		}
		$param['ignore'] = $input->ignore;
		$cacheRefreshLoader = ME_DAL_RefreshCacheLoader::getInstance();
		$starTime = time();
		$cacheRefreshLoader->refreshCacheObject($input->moduleName, $param)
		and die('批量刷新“' . $input->moduleName . '”模块成功！<br/>共用了<b color="red">' . 
			($useTime = (time() - $starTime)) . 's(' 
			. (floor($useTime/60) ? (floor($useTime/60) . '分钟') : '') 
			. (($useTime%60) ? ($useTime%60 . '秒') : '') . ')</b>')
		or die('刷新“' . $input->moduleName . '”模块失败！');
	}
}
